//
//  WZ66WZZBAppDelegate.m
//  WZ66WZZB
//
//  Created by Sunny on 11-5-11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "WZ66WZZBAppDelegate.h"

#import "MainViewController.h"
#import "MagazineViewController.h"
#import "ContentViewController.h"

#import "ParseMagazineOperation.h"
#import "ParseBlogOperation.h"

#import "FlurryAPI.h"

@implementation WZ66WZZBAppDelegate

@synthesize window;
@synthesize mainViewController;
@synthesize magazineViewController;
@synthesize contentViewController;

#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    //log the user session
	//[FlurryAPI startSession:@"HM2BEBGVHLAALS41S4U5"];
    
    // Override point for customization after application launch.
	//Default PNG Wait Time
	//[NSThread sleepForTimeInterval:1.0];
	//[[UIApplication sharedApplication] setStatusBarHidden:NO];
	
	[window addSubview:mainViewController.view];
	[window makeKeyAndVisible];
	[mainViewController presentModalViewController:magazineViewController animated:NO];
	
	[mainViewController httpMethodInit];
	NSString *magazineXmlUrl = @"http://wzzbreader.66wz.com/wzblogmagazine/magazine.xml";
	[mainViewController httpMagazineXml:magazineXmlUrl];
	
	//NotificationCenter For Magazines
	[[NSNotificationCenter defaultCenter] addObserver:self.mainViewController
                                             selector:@selector(addMagazines:)
                                                 name:kAddMagazinesNotif
                                               object:nil];
	
    [[NSNotificationCenter defaultCenter] addObserver:self.mainViewController
                                             selector:@selector(magazinesError:)
                                                 name:kMagazinesErrorNotif
                                               object:nil];
    
    
    //NotificationCenter For Blogs
	[[NSNotificationCenter defaultCenter] addObserver:self.mainViewController
                                             selector:@selector(addBlogs:)
                                                 name:kAddBlogsNotif
                                               object:nil];
	
    [[NSNotificationCenter defaultCenter] addObserver:self.mainViewController
                                             selector:@selector(blogsError:)
                                                 name:kBlogsErrorNotif
                                               object:nil];

	return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
}


- (void)applicationWillTerminate:(UIApplication *)application {
    /*
     Called when the application is about to terminate.
     See also applicationDidEnterBackground:.
     */
}


#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    /*
     Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
     */
}


- (void)dealloc {
    [mainViewController release];
	[magazineViewController release];
	
    [window release];
    [super dealloc];
}

+ (WZ66WZZBAppDelegate *)sharedAppDelegate
{
    return (WZ66WZZBAppDelegate *) [UIApplication sharedApplication].delegate;
}

@end
